<template>
  <div class="apply-wrap">
    <div class="bg-box"></div>
    <div class="tip-box">{{message}}</div>


    <!--日历组件-->
    <v-datetime :markDateMore="signList" signClass="sign" v-show="showCalendar" :passTime="passTime"
                @queryList="selectMonth"></v-datetime>

    <!--规则-->
    <div class="rule-box">
      <div class="logo-box">
        <img src="./rule.png" class="rule" onclick="return false"/>
      </div>
      <div class="title-box">
        <p>1.目前仅有部分企业支持提前领工资。</p>
        <p>2.申请提前领工资，需要入职满八个工作日。</p>
        <p>3.申请资格后，需要驻厂老师审核，驻厂老师审核成功后，员工每日到驻厂老师指定的工厂位置进行考勤签到，就可以提前领工资，领取标准如下：每天签到成功后，在夜晚12点后系统自动发放100元到您的蓝聘账户上。</p>
        <p>4.驻厂老师每天会随机对考勤签到员工的上班情况进行检查，如发现弄虚作假者，不仅取消他提前领工资的资格，还会被系统拉入黑名单。</p>
      </div>
    </div>

    <!--提示语-->
    <v-alert v-model="sendVal" :content="content"></v-alert>

    <!--微信绑定手机号-->
    <v-phone v-model="showModal" @bindPhone="bindCustomerPhone"></v-phone>
  </div>
</template>

<script>
  import alert from "../../components/alert";
  import datetime from "../../components/calendar/datetime";
  import {getUrlKey, getYearMonth, formatDate, setSessionStore, getSessionStore} from "../../config/util";
  import {baseUrl} from "../../config/env";
  import phone from "../../components/phone";

  export default {
    data() {
      return {
        sendVal: false,
        showCalendar: false,
        signList: [],
        message: "",
        content: "",
        userSign: "",
        passTime: "",
        month: getYearMonth(),
        countentPhone: "",
        showModal: false
      }
    },
    mounted() {
      //获取微信
      this.userSign = getUrlKey("success");
      this.countentPhone = getUrlKey("countentPhone"); //手机框 0弹出1不弹出
      let base64 = require('js-base64').Base64;
      if (this.userSign != "" && this.userSign != "null" && this.userSign != null) {
        setSessionStore("success", base64.encode(this.userSign));
        this.userSign = base64.decode(getSessionStore("success"));
      }

      if (this.countentPhone == "0") {
        this.showModal = true;
      } else {
        let param = this.month.substr(0, 4) + "-" + parseInt(this.month.substr(5, 6));
        this.querySignList(param);
      }
    },
    methods: {
      bindCustomerPhone(phone) {//绑定微信客户手机号
        this.$vux.loading.show({
          text: '加载中',
        });
        let time = (new Date()).getTime();
        let url = baseUrl + "/wx_user/set_phone?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        //绑定微信手机
        this.axios.get(baseUrl + "/wx_user/set_phone?sgin=" + this.userSign + "&phone=" + phone + "&userName=" + "&userUrl=" + "&auth=" + signature + "&timestamp=" + time).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0 && resultObj.data == 1) {
            let param = this.month.substr(0, 4) + "-" + parseInt(this.month.substr(5, 6));
            this.querySignList(param);
          } else {
            this.showModal = true;
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      querySignList(param) {//查询员工签到详情
        this.$vux.loading.show({
          text: '加载中',
        });
        let time = (new Date()).getTime();
        let url = baseUrl + "/work_user/get_user_sign?timestamp=" + time;
        let params = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, params);

        this.axios.get(baseUrl + "/work_user/get_user_sign?sgin=" + this.userSign + "&check=" + param + "&auth=" + signature + "&timestamp=" + time).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0) {
            let day = resultObj.data.day;
            let money = resultObj.data.money;
            this.passTime = formatDate(new Date(resultObj.data.time), "yyyy-MM-dd");
            this.message = `本月已签到${day}天，已提前领取${money}元工资！`;
            this.signList = [];
            if (resultObj.data.list != null && resultObj.data.list.length > 0) {
              for (var i = 0, length = resultObj.data.list.length; i < length; i++) {
                this.signList.push(resultObj.data.list[i].workTime);
              }
              this.showCalendar = true;
            } else {
              this.showCalendar = true;
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch((error) => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      selectMonth(month) {//根据月份查询
        this.querySignList(month);
      }
    },
    components: {
      "v-alert": alert,
      "v-datetime": datetime,
      "v-phone": phone
    },
  }
</script>

<style lang="stylus" scoped>
  @import "../../assets/stylus/mixin.styl"

  .apply-wrap
    wh(100%, auto)
    .bg-box
      position: relative
      margin: 0 auto
      wh(96.67%, 5.467rem)
      bg-image("../daymoney/bg.png", 100%, 100%)
    .tip-box
      fj(center, center)
      margin: 0 auto
      wh(90%, 1.44rem)
      size-color(0.4rem, rgba(255, 96, 96, 1))
      font-weight: 500
    .rule-box
      margin: 0 auto
      background: rgba(234, 246, 255, 1)
      border-radius(0.133rem)
      wh(94.67%, 8.8rem)
      margin-bottom: 0.2rem
      .logo-box
        margin: 0 auto
        wh(5.467rem, 0.44rem)
        padding-top: 0.587rem
        margin-bottom: 0.533rem
        .rule
          wh(100%, 100%)
      .title-box
        width: 96%
        margin: 0 auto
        size-color(0.347rem, #666666)
        p
          line-height: 0.4rem
          margin-bottom: 0.267rem
          &:nth-child(4)
            margin-bottom: 0.24rem
    .calendar-item >>> .sign
      position: relative
      border: 1px solid rgba(60, 175, 255, 1)
      border-radius(50%)
</style>

